﻿using System.Net;
using Rosetta.Default.Net;

namespace Rosetta.Default.AddIns.Net
{
    public sealed class Downloader : Converter
    {
        #region Fields

        private static readonly WebClient client = new WebClient();

        #endregion

        #region Constructors

        public Downloader()
            : base("Downloader")
        {
            Category = "Net";

            Add<WebAddress, byte[]>("GetBytes", GetBytes);
            Add<WebAddress, string>("GetString", GetString);
        }

        #endregion

        #region Class Methods

        private static byte[] GetBytes(WebAddress address)
        {
            return client.DownloadData(address.Uri);
        }

        private static string GetString(WebAddress address)
        {
            return client.DownloadString(address.Uri);
        }

        #endregion
    }
}